package com.jh3502.vivo.function.author;

import android.support.annotation.NonNull;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jh3502.vivo.base.BaseCallback;
import com.jh3502.vivo.base.BaseJson;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.base.BaseView;

import java.util.List;
import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class AuthorPresenter extends BasePresenter<AuthorPresenter.AuthorView> {
    AuthorModel mAuthorModel;

    AuthorView mAuthorView;


    public void setAuthorView(AuthorView mAuthorView) {
        this.mAuthorView = mAuthorView;

    }

    public void toFindPermissList() {
        mAuthorView.showLoadingDialog();
        if (mAuthorModel == null) {
            mAuthorModel = new AuthorModel(mAuthorView.getActContext());
        }

        mAuthorModel.findPermissList(new BaseCallback(mAuthorView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mAuthorView.findPermissListSuccess(baseJson.getObj().toString());
            }
        });
    }

    public void toFindMyEntrust() {
        mAuthorView.showLoadingDialog();
        if (mAuthorModel == null) {
            mAuthorModel = new AuthorModel(mAuthorView.getActContext());
        }

        mAuthorModel.findMyEntrust(new BaseCallback(mAuthorView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                List<AuthorListBean> dataList = new Gson().fromJson(baseJson.getObj().toString(),
                        new TypeToken<List<AuthorListBean>>() {
                        }.getType());
                mAuthorView.findMyEntrustSuccess(dataList);
            }
        });
    }

    public void toSubmitEntrust(Map<String, Object> body) {
        mAuthorView.showLoadingDialog();
        if (mAuthorModel == null) {
            mAuthorModel = new AuthorModel(mAuthorView.getActContext());
        }

        mAuthorModel.submitEntrust(body, new BaseCallback(mAuthorView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mAuthorView.submitEntrustSuccess();
            }
        });
    }

    public void toDelEntrust(Map<String, Object> body) {
        mAuthorView.showLoadingDialog();
        if (mAuthorModel == null) {
            mAuthorModel = new AuthorModel(mAuthorView.getActContext());
        }

        mAuthorModel.delEntrust(body, new BaseCallback(mAuthorView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mAuthorView.delEntrustSuccess();
            }
        });
    }

    public void toEnableEntrust(Map<String, Object> body) {
        mAuthorView.showLoadingDialog();
        if (mAuthorModel == null) {
            mAuthorModel = new AuthorModel(mAuthorView.getActContext());
        }

        mAuthorModel.enableEntrust(body, new BaseCallback(mAuthorView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mAuthorView.enableEntrustSuccess();
            }
        });
    }

    @Override
    public void cancelCall() {

    }

    public interface AuthorView extends BaseView {

        void findPermissListSuccess(String s);

        void submitEntrustSuccess();

        void findMyEntrustSuccess(List<AuthorListBean> dataList);

        void delEntrustSuccess();

        void enableEntrustSuccess();
    }

}
